package memo.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import memo.pojo.ListMemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import approve.action.R;

public class Memo_listviewadapter extends BaseAdapter implements OnClickListener{
	Context context;
	List<ListMemo> lstMemo;
	String createDate;
	LinearLayout flag = null;
	

	public Memo_listviewadapter(Context context, List<ListMemo> lstMemo,
			String createDate) {
		super();
		this.context = context;
		this.lstMemo = lstMemo;
		this.createDate = createDate;
	}

	@Override
	public int getCount() {
		return lstMemo.size();
	}

	@Override
	public Object getItem(int arg0) {
		return lstMemo.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ListMemo memo = lstMemo.get(position);
		ViewHolder holder = null;
		if(convertView==null){
			holder = new ViewHolder();
			
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=inflater.inflate(R.layout.memo_listviewadapter, parent,false);
			
			holder.titleMemo=(TextView)convertView.findViewById(R.id.titleMemo);
			holder.creDate = (TextView)convertView.findViewById(R.id.createDate);
			
			convertView.setBackgroundResource(R.drawable.list_selector);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		
//		final LinearLayout idLinearnerMemo = (LinearLayout)convertView.findViewById(R.id.idLinearnerMemo);
		
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		holder.titleMemo.setText(memo.getTitle());
		holder.creDate.setText(createDate + ": " + format.format(memo.getCreatedDate()));
		
		return convertView;
	}

	@Override
	public void onClick(View arg0) {
		
	}
	
	public static class ViewHolder{
		TextView titleMemo,creDate;
	}

}
